package models;

import java.util.*;
import javax.persistence.*;

import play.db.ebean.*;
import play.data.format.*;
import play.data.validation.*;

import com.avaje.ebean.*;

/**
 * Stop entity managed by Ebean
 */
@Entity 
@Table(name="stops")
public class Stop extends Model {

    @Id
    public String stop_id;
    
    public String stop_code;
    
    @Constraints.Required
    public String stop_name;
    
    public String stop_desc;
    
    public String platform_code;
    
    @Constraints.Required
    public String stop_lat;
    
    @Constraints.Required
    public String stop_lon;
    
    public String zone_id;
    
    public String stop_url;
    
    public String location_type;
    
    public String parent_station;
    
    public static Model.Finder<String,Stop> find = new Model.Finder(String.class, Stop.class);
    
    /**
     * Retrieve all stops.
     */
    public static List<Stop> findAll() {
        return find.all();
    }
    
    /**
     * Retrieve stop by a stop_id.
     */
    public static Stop findById(String stop_id) {
        return find.byId(stop_id);
    }

    /**
     * Retrieve stops by a stop_name.
     */
    public static List<Stop> findByName(String stop_name) {
        return find.where().like("stop_name", "%, " + stop_name + "%").findList();
    }
    
    /**
     * Retrieve all stop stop_times orderBy departure_time.
     */
    public List<StopTime> findStopTimes() {
        return StopTime.find
            .where()
            .eq("stop_id", this.stop_id)
            .orderBy("departure_time")
            .findList();
    }

}

